import { Pipe, PipeTransform } from '@angular/core';

/**
 * 根据传入的分隔符进行分割，返回数组
 */
@Pipe({ name: 'split' })
export class SplitPipe implements PipeTransform {
  transform(value, args: string[]): any {
    const result = [];
    let separator = ',';
    if (args && args.length > 0) {
      separator = args[0];
    }
    if (value && value !== '') {
      const arr = value.split(separator);
      arr.forEach(a => {
        if (a !== '') {
          result.push(a);
        }
      });
    }
    return result;
  }
}
